<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>20 S | Glossary</title>
<meta name="author" content="psyTeachR Team">
<meta name="description" content="20.1 sample A subset of the population that you wish to make an inference about through your test. The sample is a smaller group obtained from your population but it is key that the sample is...">
<meta name="generator" content="bookdown 0.24 with bs4_book()">
<meta property="og:title" content="20 S | Glossary">
<meta property="og:type" content="book">
<meta property="og:url" content="https://psyteachr.github.io/glossary/s.html">
<meta property="og:image" content="https://psyteachr.github.io/glossary/images/logos/logo.png">
<meta property="og:description" content="20.1 sample A subset of the population that you wish to make an inference about through your test. The sample is a smaller group obtained from your population but it is key that the sample is...">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="20 S | Glossary">
<meta name="twitter:description" content="20.1 sample A subset of the population that you wish to make an inference about through your test. The sample is a smaller group obtained from your population but it is key that the sample is...">
<meta name="twitter:image" content="https://psyteachr.github.io/glossary/images/logos/logo.png">
<!-- JS --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js" integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A==" crossorigin="anonymous"></script><script src="https://kit.fontawesome.com/6ecbd6c532.js" crossorigin="anonymous"></script><script src="libs/header-attrs-2.11/header-attrs.js"></script><script src="libs/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="libs/bootstrap-4.6.0/bootstrap.min.css" rel="stylesheet">
<script src="libs/bootstrap-4.6.0/bootstrap.bundle.min.js"></script><script src="libs/bs3compat-0.3.1.9000/transition.js"></script><script src="libs/bs3compat-0.3.1.9000/tabs.js"></script><script src="libs/bs3compat-0.3.1.9000/bs3compat.js"></script><link href="libs/bs4_book-1.0.0/bs4_book.css" rel="stylesheet">
<script src="libs/bs4_book-1.0.0/bs4_book.js"></script><script src="libs/kePrint-0.0.1/kePrint.js"></script><link href="libs/lightable-0.0.1/lightable.css" rel="stylesheet">
<!-- Global site tag (gtag.js) - Google Analytics --><script async src="https://www.googletagmanager.com/gtag/js?id=G-6NP3MF25W3"></script><script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'G-6NP3MF25W3');
    </script><script src="https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js" integrity="sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js" integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww==" crossorigin="anonymous"></script><!-- CSS --><link rel="stylesheet" href="include/psyteachr.css">
<link rel="stylesheet" href="include/webex.css">
<link rel="stylesheet" href="include/style.css">
</head>
<body data-spy="scroll" data-target="#toc">

<div class="container-fluid">
<div class="row">
  <header class="col-sm-12 col-lg-3 sidebar sidebar-book"><a class="sr-only sr-only-focusable" href="#content">Skip to main content</a>

    <div class="d-flex align-items-start justify-content-between">
      <h1>
        <a href="index.html" title="">Glossary</a>
      </h1>
      <button class="btn btn-outline-primary d-lg-none ml-2 mt-1" type="button" data-toggle="collapse" data-target="#main-nav" aria-expanded="true" aria-controls="main-nav"><i class="fas fa-bars"></i><span class="sr-only">Show table of contents</span></button>
    </div>

    <div id="main-nav" class="collapse-lg">
      <form role="search">
        <input id="search" class="form-control" type="search" placeholder="Search" aria-label="Search">
</form>

      <nav aria-label="Table of contents"><h2>Table of contents</h2>
        <ul class="book-toc list-unstyled">
<li><a class="" href="index.html">Overview</a></li>
<li><a class="" href="symbols.html"><span class="header-section-number">1</span> Symbols</a></li>
<li><a class="" href="a.html"><span class="header-section-number">2</span> A</a></li>
<li><a class="" href="b.html"><span class="header-section-number">3</span> B</a></li>
<li><a class="" href="c.html"><span class="header-section-number">4</span> C</a></li>
<li><a class="" href="d.html"><span class="header-section-number">5</span> D</a></li>
<li><a class="" href="e.html"><span class="header-section-number">6</span> E</a></li>
<li><a class="" href="f.html"><span class="header-section-number">7</span> F</a></li>
<li><a class="" href="g.html"><span class="header-section-number">8</span> G</a></li>
<li><a class="" href="h.html"><span class="header-section-number">9</span> H</a></li>
<li><a class="" href="i.html"><span class="header-section-number">10</span> I</a></li>
<li><a class="" href="j.html"><span class="header-section-number">11</span> J</a></li>
<li><a class="" href="k.html"><span class="header-section-number">12</span> K</a></li>
<li><a class="" href="l.html"><span class="header-section-number">13</span> L</a></li>
<li><a class="" href="m.html"><span class="header-section-number">14</span> M</a></li>
<li><a class="" href="n.html"><span class="header-section-number">15</span> N</a></li>
<li><a class="" href="o.html"><span class="header-section-number">16</span> O</a></li>
<li><a class="" href="p.html"><span class="header-section-number">17</span> P</a></li>
<li><a class="" href="q.html"><span class="header-section-number">18</span> Q</a></li>
<li><a class="" href="r.html"><span class="header-section-number">19</span> R</a></li>
<li><a class="active" href="s.html"><span class="header-section-number">20</span> S</a></li>
<li><a class="" href="t.html"><span class="header-section-number">21</span> T</a></li>
<li><a class="" href="u.html"><span class="header-section-number">22</span> U</a></li>
<li><a class="" href="v.html"><span class="header-section-number">23</span> V</a></li>
<li><a class="" href="w.html"><span class="header-section-number">24</span> W</a></li>
<li><a class="" href="x.html"><span class="header-section-number">25</span> X</a></li>
<li><a class="" href="y.html"><span class="header-section-number">26</span> Y</a></li>
<li><a class="" href="z.html"><span class="header-section-number">27</span> Z</a></li>
</ul>

        <div class="book-extra">
          <p><a id="book-repo" href="https://github.com/psyteachr/glossary">View book source <i class="fab fa-github"></i></a></p>
        </div>
      </nav>
</div>
  </header><main class="col-sm-12 col-md-9 col-lg-7" id="content"><div id="s" class="section level1" number="20">
<h1>
<span class="header-section-number">20</span> S<a class="anchor" aria-label="anchor" href="#s"><i class="fas fa-link"></i></a>
</h1>

<div id="sample" class="section level2" number="20.1">
<h2>
<span class="header-section-number">20.1</span> sample<a class="anchor" aria-label="anchor" href="#sample"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>A subset of the <a href="p.html#population">population</a> that you wish to make an inference about through your test.</dfn></p>
<p>The sample is a smaller group obtained from your population but it is key that the sample is representative of the population.</p>
<p>As in most instances it is realistically impossible to test all members of a population, a sample is derived, that represents the population of interest, from the population. The sample should have the same demographic characteristics as the population for example. If your sample is not representative of the population then any conclusions derived from your test are invalid.</p>
<div class="info">
<p>If the population is small enough to feasibly test in full, e.g. all students in a final year Psychology class, then your sample and the population are the same.</p>
</div>
<p>For an interesting paper on populations, samples and generalisability, see:</p>
<ul>
<li>Simons, D. J., Shoda, Y., &amp; Lindsay, D. S. (2017). Constraints on Generality (COG): A Proposed Addition to All Empirical Papers. Perspectives on Psychological Science, 12(6), 1123–1128. {doi: 10.1177/1745691617708630}(<a href="https://doi.org/10.1177/1745691617708630" class="uri">https://doi.org/10.1177/1745691617708630</a>){target="_blank"}}</li>
</ul>
</div>
<div id="scientific-notation" class="section level2" number="20.2">
<h2>
<span class="header-section-number">20.2</span> scientific notation<a class="anchor" aria-label="anchor" href="#scientific-notation"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>A number format for working with very large or small numbers.</dfn></p>
<p>Numbers are most commonly written in decimal notation, like <code>3.145</code> or <code>365</code>. However, when numbers are very large or small, it's difficult to read or write them correctly.</p>
<p>For example, Avogadro's constant, the number of particles contained in one mole of any substance,is equal to 602,252,000,000,000,000,000,000. The commas make it a little easier to parse when reading, but you can't use those in coding. The scientific notation is <span class="math inline">\(6.02x10^{23}\)</span>, which means the you multiply 6.02 times the number that is 1 with 23 zeros after it (or move the decimal place in 6.02 23 places to the right). In R, this notation looks like <code>6.02e23</code>.</p>
<p>Negative numbers move the decimal place to the left. For example, Wyler's constant in physics is <code>1.05e-109</code>, or a decimal place followed by 108 zeros before you get to the first non-zero digit.</p>
<div class="sourceCode" id="cb191"><pre class="downlit sourceCode r">
<code class="sourceCode R">    <span class="fl">0.0001</span> <span class="op">==</span> <span class="fl">1e-4</span>
    <span class="fl">0.001</span>  <span class="op">==</span> <span class="fl">1e-3</span>
    <span class="fl">0.01</span>   <span class="op">==</span> <span class="fl">1e-2</span>
    <span class="fl">0.1</span>    <span class="op">==</span> <span class="fl">1e-1</span>
    <span class="fl">1</span>      <span class="op">==</span> <span class="fl">1e0</span>
   <span class="fl">10</span>      <span class="op">==</span> <span class="fl">1e1</span>
  <span class="fl">100</span>      <span class="op">==</span> <span class="fl">1e2</span>
 <span class="fl">1000</span>      <span class="op">==</span> <span class="fl">1e3</span>
<span class="fl">10000</span>      <span class="op">==</span> <span class="fl">1e4</span></code></pre></div>
<p>You can format numbers with scientific notation in R using the function <code><a href="https://rdrr.io/r/base/formatc.html">formatC()</a></code>. This turns them into text that you can use n inline code, but you can't use as a number anymore.</p>
<div class="sourceCode" id="cb192"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">x</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">123456789</span>, <span class="fl">0.06789</span>, <span class="fl">0.000000012</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/base/formatc.html">formatC</a></span><span class="op">(</span><span class="va">x</span>, format <span class="op">=</span> <span class="st">"e"</span>, digits <span class="op">=</span> <span class="fl">2</span><span class="op">)</span>
<span class="co">#&gt; [1] "1.23e+08" "6.79e-02" "1.20e-08"</span></code></pre></div>
<p>Model output can often contain numbers in scientific notation. To change the threshold at which large or small numbers display with scientific notation, set the <code>scipen</code> option at the top of a script. A value of 0 means that R will use scientific notation whenever that representation takes less space than the decimal representation. Larger values make decimal notation more likely and smaller values make scientific notation more likely.</p>
<div class="sourceCode" id="cb193"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">test</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op">(</span><span class="fl">1000000</span>,
              <span class="fl">100000</span>, 
               <span class="fl">10000</span>, 
                <span class="fl">1000</span>, 
                 <span class="fl">100</span>, 
                  <span class="fl">10</span>, 
                   <span class="fl">1</span>, 
                   <span class="fl">0.1</span>, 
                   <span class="fl">0.01</span>, 
                   <span class="fl">0.001</span>, 
                   <span class="fl">0.0001</span>,
                   <span class="fl">0.00001</span>,
                   <span class="fl">0.000001</span><span class="op">)</span></code></pre></div>
<div class="sourceCode" id="cb194"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="https://rdrr.io/r/base/options.html">options</a></span><span class="op">(</span>scipen <span class="op">=</span> <span class="fl">1</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/utils/str.html">str</a></span><span class="op">(</span><span class="va">test</span><span class="op">)</span>
<span class="co">#&gt; List of 13</span>
<span class="co">#&gt;  $ : num 1e+06</span>
<span class="co">#&gt;  $ : num 100000</span>
<span class="co">#&gt;  $ : num 10000</span>
<span class="co">#&gt;  $ : num 1000</span>
<span class="co">#&gt;  $ : num 100</span>
<span class="co">#&gt;  $ : num 10</span>
<span class="co">#&gt;  $ : num 1</span>
<span class="co">#&gt;  $ : num 0.1</span>
<span class="co">#&gt;  $ : num 0.01</span>
<span class="co">#&gt;  $ : num 0.001</span>
<span class="co">#&gt;  $ : num 0.0001</span>
<span class="co">#&gt;  $ : num 1e-05</span>
<span class="co">#&gt;  $ : num 1e-06</span></code></pre></div>
<div class="sourceCode" id="cb195"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="https://rdrr.io/r/base/options.html">options</a></span><span class="op">(</span>scipen <span class="op">=</span> <span class="fl">0</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/utils/str.html">str</a></span><span class="op">(</span><span class="va">test</span><span class="op">)</span>
<span class="co">#&gt; List of 13</span>
<span class="co">#&gt;  $ : num 1e+06</span>
<span class="co">#&gt;  $ : num 1e+05</span>
<span class="co">#&gt;  $ : num 10000</span>
<span class="co">#&gt;  $ : num 1000</span>
<span class="co">#&gt;  $ : num 100</span>
<span class="co">#&gt;  $ : num 10</span>
<span class="co">#&gt;  $ : num 1</span>
<span class="co">#&gt;  $ : num 0.1</span>
<span class="co">#&gt;  $ : num 0.01</span>
<span class="co">#&gt;  $ : num 0.001</span>
<span class="co">#&gt;  $ : num 1e-04</span>
<span class="co">#&gt;  $ : num 1e-05</span>
<span class="co">#&gt;  $ : num 1e-06</span></code></pre></div>
<div class="sourceCode" id="cb196"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="https://rdrr.io/r/base/options.html">options</a></span><span class="op">(</span>scipen <span class="op">=</span> <span class="op">-</span><span class="fl">1</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/utils/str.html">str</a></span><span class="op">(</span><span class="va">test</span><span class="op">)</span>
<span class="co">#&gt; List of 13</span>
<span class="co">#&gt;  $ : num 1e+06</span>
<span class="co">#&gt;  $ : num 1e+05</span>
<span class="co">#&gt;  $ : num 1e+04</span>
<span class="co">#&gt;  $ : num 1000</span>
<span class="co">#&gt;  $ : num 100</span>
<span class="co">#&gt;  $ : num 10</span>
<span class="co">#&gt;  $ : num 1</span>
<span class="co">#&gt;  $ : num 0.1</span>
<span class="co">#&gt;  $ : num 0.01</span>
<span class="co">#&gt;  $ : num 1e-03</span>
<span class="co">#&gt;  $ : num 1e-04</span>
<span class="co">#&gt;  $ : num 1e-05</span>
<span class="co">#&gt;  $ : num 1e-06</span></code></pre></div>

</div>
<div id="scope" class="section level2" number="20.3">
<h2>
<span class="header-section-number">20.3</span> scope<a class="anchor" aria-label="anchor" href="#scope"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>The <a href="e.html#environment">environment</a> where an <a href="o.html#object">object</a> is available</dfn></p>
<p>The main thing you need to know about scope involves writing your own <a href="f.html#function">functions</a>. Objects created inside a function are only available inside the function and not outside.</p>
<div class="sourceCode" id="cb197"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">y</span> <span class="op">&lt;-</span> <span class="fl">5</span> <span class="co"># this y is global</span>

<span class="va">x</span> <span class="op">&lt;-</span> <span class="kw">function</span><span class="op">(</span><span class="op">)</span> <span class="op">{</span>
  <span class="va">y</span> <span class="op">&lt;-</span> <span class="fl">10</span> <span class="co"># this y is local</span>
  <span class="kw"><a href="https://rdrr.io/r/base/function.html">return</a></span><span class="op">(</span><span class="va">y</span><span class="op">)</span>
<span class="op">}</span>

<span class="fu"><a href="https://rdrr.io/pkg/ggplot2/man/aes_position.html">x</a></span><span class="op">(</span><span class="op">)</span> <span class="co"># returns the local value of y</span>
<span class="co">#&gt; [1] 10</span>
<span class="va">y</span> <span class="co"># returns the global value of y</span>
<span class="co">#&gt; [1] 5</span></code></pre></div>
<p>If you have arguments to a function, they are local variables inside the function and their values will overwrite any global variables with the same name.</p>
<div class="sourceCode" id="cb198"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">y</span> <span class="op">&lt;-</span> <span class="fl">5</span> <span class="co"># this y is global</span>

<span class="va">x</span> <span class="op">&lt;-</span> <span class="kw">function</span><span class="op">(</span><span class="va">y</span><span class="op">)</span> <span class="op">{</span>
  <span class="va">y</span> <span class="op">&lt;-</span> <span class="va">y</span> <span class="op">+</span> <span class="fl">1</span> <span class="co"># this uses the local value of y</span>
  <span class="kw"><a href="https://rdrr.io/r/base/function.html">return</a></span><span class="op">(</span><span class="va">y</span><span class="op">)</span>
<span class="op">}</span>

<span class="fu"><a href="https://rdrr.io/pkg/ggplot2/man/aes_position.html">x</a></span><span class="op">(</span><span class="fl">10</span><span class="op">)</span> <span class="co"># returns 10 + 1</span>
<span class="co">#&gt; [1] 11</span>
<span class="va">y</span>     <span class="co"># y is still 5</span>
<span class="co">#&gt; [1] 5</span></code></pre></div>

</div>
<div id="script" class="section level2" number="20.4">
<h2>
<span class="header-section-number">20.4</span> script<a class="anchor" aria-label="anchor" href="#script"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>A plain-text file that contains commands in a coding language, such as R.</dfn></p>

</div>
<div id="semi_join" class="section level2" number="20.5">
<h2>
<span class="header-section-number">20.5</span> semi_join<a class="anchor" aria-label="anchor" href="#semi_join"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>A <a href="f.html#filtering-joins">filtering join</a> that returns all rows from the left table where there are matching values in the right table, keeping just columns from the left table.</dfn></p>
<div class="figure" style="text-align: center">
<span style="display:block;" id="fig:semi-join"></span>
<img src="images/joins/semi_join.png" alt="Semi Join" width="100%"><p class="caption">
Figure 20.1: Semi Join
</p>
</div>
<p>This is useful when you have a table of data that contains IDs of data that passes your exclusion criteria.</p>
<div class="sourceCode" id="cb199"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">all_data</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/tibble/man/tibble.html">tibble</a></span><span class="op">(</span>
  id <span class="op">=</span> <span class="fl">1</span><span class="op">:</span><span class="fl">5</span>,
  x <span class="op">=</span> <span class="va">LETTERS</span><span class="op">[</span><span class="fl">1</span><span class="op">:</span><span class="fl">5</span><span class="op">]</span>
<span class="op">)</span>

<span class="va">to_keep</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/tibble/man/tibble.html">tibble</a></span><span class="op">(</span>
  id <span class="op">=</span> <span class="fl">2</span><span class="op">:</span><span class="fl">4</span>
<span class="op">)</span>

<span class="va">data</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/dplyr/man/filter-joins.html">semi_join</a></span><span class="op">(</span><span class="va">all_data</span>, <span class="va">to_keep</span>, by <span class="op">=</span> <span class="st">"id"</span><span class="op">)</span></code></pre></div>
<div class="inline-table"><table class="table table-sm">
<thead><tr>
<th style="text-align:right;">
id
</th>
<th style="text-align:left;">
x
</th>
</tr></thead>
<tbody>
<tr>
<td style="text-align:right;">
2
</td>
<td style="text-align:left;">
B
</td>
</tr>
<tr>
<td style="text-align:right;">
3
</td>
<td style="text-align:left;">
C
</td>
</tr>
<tr>
<td style="text-align:right;">
4
</td>
<td style="text-align:left;">
D
</td>
</tr>
</tbody>
</table></div>
<p>See <a href="j.html#joins">joins</a> for other types of joins and further resources.</p>

</div>
<div id="server" class="section level2" number="20.6">
<h2>
<span class="header-section-number">20.6</span> server<a class="anchor" aria-label="anchor" href="#server"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>This is the part of a Shiny app that works with logic.</dfn></p>
<p>The server is a function that processes the user's input in the <a href="u.html#ui">UI</a>, and allows the app to render appropriate output. See <a href="https://shiny.rstudio.com/articles/basics.html" target="_blank">this shiny basics article</a> for more.</p>

</div>
<div id="sesoi" class="section level2" number="20.7">
<h2>
<span class="header-section-number">20.7</span> SESOI<a class="anchor" aria-label="anchor" href="#sesoi"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>Smallest Effect Size of Interest: the smallest effect that is theoretically or practically meaningful</dfn></p>
<p>See <a href="https://doi.org/10.1177/2515245918770963">Equivalence Testing for Psychological Research: A Tutorial</a> for a tutorial on methods for choosing an SESOI.</p>
<p>Lakens, D. (2017a). Equivalence tests: A practical primer for t tests, correlations, and meta-analyses. Social Psychological &amp; Personality Science, 8, 355–362. <a href="https://doi.org/10.1177/1948550617697177">doi:10.1177/1948550617697177</a></p>

</div>
<div id="set-operations" class="section level2" number="20.8">
<h2>
<span class="header-section-number">20.8</span> set operations<a class="anchor" aria-label="anchor" href="#set-operations"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>Functions that compare two tables and return rows that match (intersect), are in either table (union), or are in one table but not the other (setdiff).</dfn></p>
<p>The examples below use two small datasets. <code>a</code> has <code>id</code>s 1 to 5, and <code>b</code> has <code>id</code>s 3 to 7.</p>
<div class="sourceCode" id="cb200"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">a</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/tibble/man/tibble.html">tibble</a></span><span class="op">(</span>id <span class="op">=</span> <span class="fl">1</span><span class="op">:</span><span class="fl">5</span><span class="op">)</span>
<span class="va">b</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/tibble/man/tibble.html">tibble</a></span><span class="op">(</span>id <span class="op">=</span> <span class="fl">3</span><span class="op">:</span><span class="fl">7</span><span class="op">)</span></code></pre></div>
<p><code><a href="https://rdrr.io/pkg/generics/man/setops.html">intersect()</a></code> returns all rows in two tables that match exactly. The columns don't have to be in the same order.</p>
<div class="sourceCode" id="cb201"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu">dplyr</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/generics/man/setops.html">intersect</a></span><span class="op">(</span><span class="va">a</span>, <span class="va">b</span><span class="op">)</span></code></pre></div>
<div class="kable-table">
<div class="inline-table"><table class="table table-sm">
<thead><tr>
<th style="text-align:right;">
id
</th>
</tr></thead>
<tbody>
<tr>
<td style="text-align:right;">
3
</td>
</tr>
<tr>
<td style="text-align:right;">
4
</td>
</tr>
<tr>
<td style="text-align:right;">
5
</td>
</tr>
</tbody>
</table></div>
</div>
<p><code><a href="https://rdrr.io/pkg/generics/man/setops.html">union()</a></code> returns all the rows from both tables, removing duplicate rows.</p>
<div class="sourceCode" id="cb202"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu">dplyr</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/generics/man/setops.html">union</a></span><span class="op">(</span><span class="va">a</span>, <span class="va">b</span><span class="op">)</span></code></pre></div>
<div class="kable-table">
<div class="inline-table"><table class="table table-sm">
<thead><tr>
<th style="text-align:right;">
id
</th>
</tr></thead>
<tbody>
<tr>
<td style="text-align:right;">
1
</td>
</tr>
<tr>
<td style="text-align:right;">
2
</td>
</tr>
<tr>
<td style="text-align:right;">
3
</td>
</tr>
<tr>
<td style="text-align:right;">
4
</td>
</tr>
<tr>
<td style="text-align:right;">
5
</td>
</tr>
<tr>
<td style="text-align:right;">
6
</td>
</tr>
<tr>
<td style="text-align:right;">
7
</td>
</tr>
</tbody>
</table></div>
</div>
<p><code>setdiff</code> returns rows that are in the first table, but not in the second table.</p>
<div class="sourceCode" id="cb203"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu">dplyr</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/generics/man/setops.html">setdiff</a></span><span class="op">(</span><span class="va">a</span>, <span class="va">b</span><span class="op">)</span></code></pre></div>
<div class="kable-table">
<div class="inline-table"><table class="table table-sm">
<thead><tr>
<th style="text-align:right;">
id
</th>
</tr></thead>
<tbody>
<tr>
<td style="text-align:right;">
1
</td>
</tr>
<tr>
<td style="text-align:right;">
2
</td>
</tr>
</tbody>
</table></div>
</div>
<div class="warning">
<p>If you've forgotten to load dplyr or the tidyverse, <a href="b#base-r">base R</a> also has these functions. You will either get an error message or unexpected output if you try to use them with data tables.</p>
</div>

</div>
<div id="shiny" class="section level2" number="20.9">
<h2>
<span class="header-section-number">20.9</span> Shiny<a class="anchor" aria-label="anchor" href="#shiny"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>An R package that builds interactive web apps</dfn></p>
<ul>
<li>
<a href="https://shiny.rstudio.com/" target="_blank">Shiny</a> website</li>
<li><a href="https://psyteachr.github.io/shiny-tutorials/" target="_blank">psyTeachR Shiny Tutorials</a></li>
</ul>
</div>
<div id="shinydashboard" class="section level2" number="20.10">
<h2>
<span class="header-section-number">20.10</span> shinydashboard<a class="anchor" aria-label="anchor" href="#shinydashboard"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>A package for R that builds on <a href="s.html#shiny">Shiny</a> for more flexible and visually appealing <a href="u.html#ui">UI</a>s.</dfn></p>
<p><a href="https://rstudio.github.io/shinydashboard/" target="_blank">Shiny Dashboard or shinydashboard</a> can be installed with <code>install.packages("shinydashboard")</code>, and can be loaded with <code><a href="http://rstudio.github.io/shinydashboard/">library(shinydashboard)</a></code>. The <a href="https://rstudio.github.io/shinydashboard/get_started.html" target="_blank">shinydashboard documentation</a> is a great introduction to this package.</p>

</div>
<div id="significant" class="section level2" number="20.11">
<h2>
<span class="header-section-number">20.11</span> significant<a class="anchor" aria-label="anchor" href="#significant"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>The conclusion when the p-value is less than the critical alpha. </dfn></p>

</div>
<div id="simulation" class="section level2" number="20.12">
<h2>
<span class="header-section-number">20.12</span> simulation<a class="anchor" aria-label="anchor" href="#simulation"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>Generating data from summary parameters</dfn></p>

</div>
<div id="single-brackets" class="section level2" number="20.13">
<h2>
<span class="header-section-number">20.13</span> single brackets<a class="anchor" aria-label="anchor" href="#single-brackets"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>A pair of square brackets used to select a subset from a <a href="c.html#container">container</a> like a <a href="l.html#list">list</a>, <a href="d.html#data-frame">data frame</a>, or <a href="m.html#matrix">matrix</a> (e.g., data[1, ]).</dfn></p>
<div class="sourceCode" id="cb204"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">secret_code</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">16</span>, <span class="fl">19</span>, <span class="fl">25</span>, <span class="fl">20</span>, <span class="fl">5</span>, <span class="fl">1</span>, <span class="fl">3</span>, <span class="fl">8</span>, <span class="fl">18</span><span class="op">)</span>

<span class="va">LETTERS</span><span class="op">[</span><span class="va">secret_code</span><span class="op">]</span>
<span class="co">#&gt; [1] "P" "S" "Y" "T" "E" "A" "C" "H" "R"</span></code></pre></div>
<p>See <a href="b.html#brackets">brackets</a> for an explanation of the difference between single and <a href="d.html#double-brackets">double</a> brackets.</p>

</div>
<div id="slope" class="section level2" number="20.14">
<h2>
<span class="header-section-number">20.14</span> slope<a class="anchor" aria-label="anchor" href="#slope"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>A quantity that captures how much change in one variable is associated with a unit increase in another variable.</dfn></p>
<p>If you have a slope of 3, that means that a unit increase in the <span class="math inline">\(X\)</span> variable is associated with a 3 unit change in the <span class="math inline">\(Y\)</span> variable. If you have a slope of -1/2, then a unit increase in the <span class="math inline">\(X\)</span> variable is associated with a decrease of 1/2 in the <span class="math inline">\(Y\)</span> variable.</p>

</div>
<div id="standard-deviation" class="section level2" number="20.15">
<h2>
<span class="header-section-number">20.15</span> standard deviation<a class="anchor" aria-label="anchor" href="#standard-deviation"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>A <a href="d.html#descriptive">descriptive</a> statistic that measures how spread out data are relative to the mean.</dfn></p>
<p>If the data points are further from the mean, there is a higher standard deviation. Standard deviation is calculated as the square root of the <a href="v.html#variance">variance</a>.</p>
<div class="figure" style="text-align: center">
<span style="display:block;" id="fig:sd-plot"></span>
<img src="_main_files/figure-html/sd-plot-1.png" alt="Normal distributions with means of 0 and SDs of 1 (red), 2 (blue) and 3 (purple)." width="100%"><p class="caption">
Figure 20.2: Normal distributions with means of 0 and SDs of 1 (red), 2 (blue) and 3 (purple).
</p>
</div>

</div>
<div id="static" class="section level2" number="20.16">
<h2>
<span class="header-section-number">20.16</span> static<a class="anchor" aria-label="anchor" href="#static"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>Something that does not change in response to user actions</dfn></p>
<p>For example, in a <a href="s.html#shiny">shiny</a> app, the following code creates static and <a href="d.html#dynamic">dynamic</a> elements.</p>
<div class="sourceCode" id="cb205"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">static</span> <span class="op">&lt;-</span> <span class="fu">shiny</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/htmltools/man/builder.html">p</a></span><span class="op">(</span><span class="st">"This text cannot change"</span><span class="op">)</span>
<span class="va">dynamic</span> <span class="op">&lt;-</span> <span class="fu">shiny</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/shiny/man/textOutput.html">textOutput</a></span><span class="op">(</span><span class="st">"This text can change"</span><span class="op">)</span></code></pre></div>

</div>
<div id="string" class="section level2" number="20.17">
<h2>
<span class="header-section-number">20.17</span> string<a class="anchor" aria-label="anchor" href="#string"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>A piece of text inside of quotes.</dfn></p>
<p>For example, <code>"I sense the rains down in Africa"</code> is a string. Numbers inside of quotes can be a string; <code>"19"</code> is a string, while <code>19</code> is not.</p>
<p>Strings are a <a href="c.html#character">character</a> <a href="d.html#data-type">data type</a>.</p>

</div>
<div id="sum-code" class="section level2" number="20.18">
<h2>
<span class="header-section-number">20.18</span> sum code<a class="anchor" aria-label="anchor" href="#sum-code"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>A <a href="c.html#coding-scheme">coding scheme</a> for categorical variables that compares the mean for each level to the overall mean.</dfn></p>

</div>
</div>
<script>

/* update total correct if #webex-total_correct exists */
update_total_correct = function() {
  console.log("webex: update total_correct");

  if (t = document.getElementById("webex-total_correct")) {
    var correct = document.getElementsByClassName("webex-correct").length;
    var solvemes = document.getElementsByClassName("webex-solveme").length;
    var radiogroups = document.getElementsByClassName("webex-radiogroup").length;
    var selects = document.getElementsByClassName("webex-select").length;
    
    t.innerHTML = correct + " of " + (solvemes + radiogroups + selects) + " correct";
  }
}

/* webex-solution button toggling function */
b_func = function() {
  console.log("webex: toggle hide");
  
  var cl = this.parentElement.classList;
  if (cl.contains('open')) {
    cl.remove("open");
  } else {
    cl.add("open");
  }
}

/* function for checking solveme answers */
solveme_func = function(e) {
  console.log("webex: check solveme");

  var real_answers = JSON.parse(this.dataset.answer);
  var my_answer = this.value;
  var cl = this.classList;
  if (cl.contains("ignorecase")) {
    my_answer = my_answer.toLowerCase();
  }
  if (cl.contains("nospaces")) {
    my_answer = my_answer.replace(/ /g, "")
  }

  if (my_answer == "") {
    cl.remove("webex-correct");
    cl.remove("webex-incorrect");
  } else if (real_answers.includes(my_answer)) {
    cl.add("webex-correct");
    cl.remove("webex-incorrect");
  } else {
    cl.add("webex-incorrect");
    cl.remove("webex-correct");
  }

  // match numeric answers within a specified tolerance
  if(this.dataset.tol > 0){
    var tol = JSON.parse(this.dataset.tol);
    var matches = real_answers.map(x => Math.abs(x - my_answer) < tol)
    if (matches.reduce((a, b) => a + b, 0) > 0) {
      cl.add("webex-correct");
    } else {
      cl.remove("webex-correct");
    }
  }

  // added regex bit
  if (cl.contains("regex")){
    answer_regex = RegExp(real_answers.join("|"))
    if (answer_regex.test(my_answer)) {
      cl.add("webex-correct");
    }
  }

  update_total_correct();
}

/* function for checking select answers */
select_func = function(e) {
  console.log("webex: check select");
  
  var cl = this.classList
  
  /* add style */
  cl.remove("webex-incorrect");
  cl.remove("webex-correct");
  if (this.value == "answer") {
    cl.add("webex-correct");
  } else if (this.value != "blank") {
    cl.add("webex-incorrect");
  }
  
  update_total_correct();
}

/* function for checking radiogroups answers */
radiogroups_func = function(e) {
  console.log("webex: check radiogroups");

  var checked_button = document.querySelector('input[name=' + this.id + ']:checked');
  var cl = checked_button.parentElement.classList;
  var labels = checked_button.parentElement.parentElement.children;
  
  /* get rid of styles */
  for (i = 0; i < labels.length; i++) {
    labels[i].classList.remove("webex-incorrect");
    labels[i].classList.remove("webex-correct");
  }
  
  /* add style */
  if (checked_button.value == "answer") {
    cl.add("webex-correct");
  } else {
    cl.add("webex-incorrect");
  }
  
  update_total_correct();
}

window.onload = function() {
  console.log("onload");
  /* set up solution buttons */
  var buttons = document.getElementsByTagName("button");

  for (var i = 0; i < buttons.length; i++) {
    if (buttons[i].parentElement.classList.contains('webex-solution')) {
      buttons[i].onclick = b_func;
    }
  }

  /* set up webex-solveme inputs */
  var solveme = document.getElementsByClassName("webex-solveme");

  for (var i = 0; i < solveme.length; i++) {
    /* make sure input boxes don't auto-anything */
    solveme[i].setAttribute("autocomplete","off");
    solveme[i].setAttribute("autocorrect", "off");
    solveme[i].setAttribute("autocapitalize", "off");
    solveme[i].setAttribute("spellcheck", "false");
    solveme[i].value = "";

    /* adjust answer for ignorecase or nospaces */
    var cl = solveme[i].classList;
    var real_answer = solveme[i].dataset.answer;
    if (cl.contains("ignorecase")) {
      real_answer = real_answer.toLowerCase();
    }
    if (cl.contains("nospaces")) {
      real_answer = real_answer.replace(/ /g, "");
    }
    solveme[i].dataset.answer = real_answer;

    /* attach checking function */
    solveme[i].onkeyup = solveme_func;
    solveme[i].onchange = solveme_func;
  }
  
  /* set up radiogroups */
  var radiogroups = document.getElementsByClassName("webex-radiogroup");
  for (var i = 0; i < radiogroups.length; i++) {
    radiogroups[i].onchange = radiogroups_func;
  }
  
  /* set up selects */
  var selects = document.getElementsByClassName("webex-select");
  for (var i = 0; i < selects.length; i++) {
    selects[i].onchange = select_func;
  }

  update_total_correct();
}

</script><script>
$( document ).ready(function() {
  var cite = ' ';
  var psyteachr = ' <a href="https://psyteachr.github.io/"><img src="images/logos/psyteachr_logo.png" style="height: 31px; color: white;" alt="psyTeachR: Reproducible Research" /></a>';
  var license = ' <a rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/" target="blank"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/88x31.png"></a>';

  $("footer div.row div:eq(1) p").html(
    psyteachr + license + cite
  );
  
  $("#toc").appendTo($("#main-nav"));
});
</script><div class="chapter-nav">
<div class="prev"><a href="r.html"><span class="header-section-number">19</span> R</a></div>
<div class="next"><a href="t.html"><span class="header-section-number">21</span> T</a></div>
</div></main><div class="col-md-3 col-lg-2 d-none d-md-block sidebar sidebar-chapter">
    <nav id="toc" data-toggle="toc" aria-label="On this page"><h2>On this page</h2>
      <ul class="nav navbar-nav">
<li><a class="nav-link" href="#s"><span class="header-section-number">20</span> S</a></li>
<li><a class="nav-link" href="#sample"><span class="header-section-number">20.1</span> sample</a></li>
<li><a class="nav-link" href="#scientific-notation"><span class="header-section-number">20.2</span> scientific notation</a></li>
<li><a class="nav-link" href="#scope"><span class="header-section-number">20.3</span> scope</a></li>
<li><a class="nav-link" href="#script"><span class="header-section-number">20.4</span> script</a></li>
<li><a class="nav-link" href="#semi_join"><span class="header-section-number">20.5</span> semi_join</a></li>
<li><a class="nav-link" href="#server"><span class="header-section-number">20.6</span> server</a></li>
<li><a class="nav-link" href="#sesoi"><span class="header-section-number">20.7</span> SESOI</a></li>
<li><a class="nav-link" href="#set-operations"><span class="header-section-number">20.8</span> set operations</a></li>
<li><a class="nav-link" href="#shiny"><span class="header-section-number">20.9</span> Shiny</a></li>
<li><a class="nav-link" href="#shinydashboard"><span class="header-section-number">20.10</span> shinydashboard</a></li>
<li><a class="nav-link" href="#significant"><span class="header-section-number">20.11</span> significant</a></li>
<li><a class="nav-link" href="#simulation"><span class="header-section-number">20.12</span> simulation</a></li>
<li><a class="nav-link" href="#single-brackets"><span class="header-section-number">20.13</span> single brackets</a></li>
<li><a class="nav-link" href="#slope"><span class="header-section-number">20.14</span> slope</a></li>
<li><a class="nav-link" href="#standard-deviation"><span class="header-section-number">20.15</span> standard deviation</a></li>
<li><a class="nav-link" href="#static"><span class="header-section-number">20.16</span> static</a></li>
<li><a class="nav-link" href="#string"><span class="header-section-number">20.17</span> string</a></li>
<li><a class="nav-link" href="#sum-code"><span class="header-section-number">20.18</span> sum code</a></li>
</ul>

      <div class="book-extra">
        <ul class="list-unstyled">
<li><a id="book-source" href="https://github.com/psyteachr/glossary/blob/master/terms/s.Rmd">View source <i class="fab fa-github"></i></a></li>
          <li><a id="book-edit" href="https://github.com/psyteachr/glossary/edit/master/terms/s.Rmd">Edit this page <i class="fab fa-github"></i></a></li>
        </ul>
</div>
    </nav>
</div>

</div>
</div> <!-- .container -->

<footer class="bg-primary text-light mt-5"><div class="container"><div class="row">

  <div class="col-12 col-md-6 mt-3">
    <p>"<strong>Glossary</strong>" was written by psyTeachR Team. It was last built on 2022-02-27.</p>
  </div>

  <div class="col-12 col-md-6 mt-3">
    <p>This book was built by the <a class="text-light" href="https://bookdown.org">bookdown</a> R package.</p>
  </div>

</div></div>
</footer><!-- dynamically load mathjax for compatibility with self-contained --><script>
  (function () {
    var script = document.createElement("script");
    script.type = "text/javascript";
    var src = "true";
    if (src === "" || src === "true") src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-MML-AM_CHTML";
    if (location.protocol !== "file:")
      if (/^https?:/.test(src))
        src = src.replace(/^https?:/, '');
    script.src = src;
    document.getElementsByTagName("head")[0].appendChild(script);
  })();
</script><script type="text/x-mathjax-config">const popovers = document.querySelectorAll('a.footnote-ref[data-toggle="popover"]');
for (let popover of popovers) {
  const div = document.createElement('div');
  div.setAttribute('style', 'position: absolute; top: 0, left:0; width:0, height:0, overflow: hidden; visibility: hidden;');
  div.innerHTML = popover.getAttribute('data-content');

  var has_math = div.querySelector("span.math");
  if (has_math) {
    document.body.appendChild(div);
    MathJax.Hub.Queue(["Typeset", MathJax.Hub, div]);
    MathJax.Hub.Queue(function() {
      popover.setAttribute('data-content', div.innerHTML);
      document.body.removeChild(div);
    })
  }
}
</script>
</body>
</html>
